package com.aaa.controller.mht;


import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.mht.TMhtSurvey;
import com.aaa.service.mht.TMhtSurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("tMhtSurvey")
public class TMhtSurveyController {

    @Qualifier("TMhtSurveyServiceImpl")
    @Autowired
    private TMhtSurveyService tMhtSurveyService;

    @RequestMapping("addSurvey")
    @ResponseBody
    public LayData addSurvey(TMhtSurvey tMhtSurvey, HttpSession session ){
        User user = (User)session.getAttribute("user");
        tMhtSurvey.setUsername(user.getUsername());
        tMhtSurvey.setCreatetime(new Date());
        System.out.println("进入addSurvey方法");
        System.out.println("tMhtSurvey *********= " + tMhtSurvey);
        boolean b = tMhtSurveyService.addSurvey(tMhtSurvey);
        return new LayData(b);
    }
    @RequestMapping("updSurvey")
    @ResponseBody
    public LayData updSurvey(TMhtSurvey tMhtSurvey,HttpSession session ){
        User user = (User)session.getAttribute("user");
        tMhtSurvey.setUsername(user.getUsername());
        tMhtSurvey.setUpdateby(user.getUsername());
        tMhtSurvey.setUpdatetime(new Date());
        System.out.println("进入updSurvey方法");
        System.out.println("tMhtSurvey *********= " + tMhtSurvey);
        boolean b = tMhtSurveyService.updSurvey(tMhtSurvey);
        return new LayData(b);
    }
    @RequestMapping("querySurvey")
    @ResponseBody
    public LayData querySurvey(MyPage myPage, TMhtSurvey tMhtSurvey){
        return new LayData(tMhtSurveyService.querySurvey(myPage,tMhtSurvey));
    }
    @RequestMapping("delSurvey")
    @ResponseBody
    public LayData delSurvey(TMhtSurvey tMhtSurvey){
        System.out.println("进入删除Survey"+tMhtSurvey);
        return new LayData(tMhtSurveyService.delSurvey(tMhtSurvey));
    }
}
